<?php

class UID extends DedeSql
{
	private $is_log;
	
	public function __construct() 
    { 
        parent::__construct();
		$this->is_log=true;
    } 

	//插入
	public function insert($table,$dataArray) {
		$field = "";
		$value = "";
		if( !is_array($dataArray) || count($dataArray)<=0) {
			$this->halt('没有要插入的数据');
			return false;
		}
		while(list($key,$val)=each($dataArray)) {
			$field .="$key,";
			if(stripos($val, "()")===false)
				$value .="'$val',";
			else
				$value .="$val,";
		}
		$field = substr( $field,0,-1);
		$value = substr( $value,0,-1);
		$sql = "insert into $table($field) values($value)";
		//$this->write_log("插入 ".$sql);
		if(!$this->ExecuteNoneQuery($sql)) return false;
		return true;
	}

	//更新
	public function update( $table,$dataArray,$condition="") {
		if( !is_array($dataArray) || count($dataArray)<=0) {
			$this->halt('没有要更新的数据');
			return false;
		}
		$value = "";
		while( list($key,$val) = each($dataArray))
		if(stripos($val, "()")===false)
				$value .="$key ='$val',";
			else
				$value .="$key = $val,";
		//$value .= "$key = '$val',";
		$value .= substr( $value,0,-1);
		$sql = "update $table set $value where 1=1 and $condition";
		//$this->write_log("更新 ".$sql);
		if(!$this->ExecuteNoneQuery($sql)) return false;
		return true;
	}

	//删除
	public function delete( $table,$condition="") {
		if( empty($condition) ) {
			$this->halt('没有设置删除的条件');
			return false;
		}
		$sql = "delete from $table where 1=1 and $condition";
		//$this->write_log("删除 ".$sql);
		if(!$this->ExecuteNoneQuery($sql)) return false;
		return true;
	}
	//错误提示
	private function halt($msg='') {
		$msg .= "\r\n".mysql_error();
		$this->write_log($msg);
		die($msg);
	}
	//写入日志文件
	public function write_log($msg=''){
		if($this->is_log){
			$text = date("Y-m-d H:i:s")." ".$msg."\r\n";
			echo $text;
			//fwrite($this->handle,$text);
		}
	}


}




?>